//
//  UserLeadViewController.m
//  MyProject
//
//  Created by dllo on 15/9/21.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "UserLeadViewController.h"
#import "MyMainViewController.h"
#import "GoodsMainViewController.h"
#import "ElephantMainViewController.h"
#import "QualityGoodsMainViewController.h"
#import "ActicleMainViewController.h"
@interface UserLeadViewController ()<UIScrollViewDelegate>
@property (nonatomic ,retain) UIScrollView *scrollview;
@property (nonatomic ,retain) UIPageControl *page;
@end

@implementation UserLeadViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
       //self.view.backgroundColor = [UIColor greenColor];
    [self initGuide];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    if (scrollView.contentOffset.x == 0) {
        self.page.currentPage = 0;
    }
     if (scrollView.contentOffset.x == self.view.bounds.size.width) {
        self.page.currentPage = 1;
    }
    if (scrollView.contentOffset.x == self.view.bounds.size.width*2) {
        self.page.currentPage = 2;
    }
    if (scrollView.contentOffset.x == self.view.bounds.size.width*3) {
        self.page.currentPage = 3;
    }
}

- (void)initGuide
 {
        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
     self.scrollview = scrollView;
     
     self.scrollview.delegate = self;
     
        [scrollView setContentSize:CGSizeMake(self.view.bounds.size.width*4, 0)];
         [scrollView setPagingEnabled:YES];
     scrollView.bounces = NO;
     scrollView.showsHorizontalScrollIndicator = NO;
         UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
         [imageview setImage:[UIImage imageNamed:@"1.jpg"]];
        [scrollView addSubview:imageview];
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, self.view.bounds.size.height/2, self.view.bounds.size.width-40, self.view.bounds.size.height/2)];
     [imageview addSubview:label];
     
         UIImageView *imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    [imageview1 setImage:[UIImage imageNamed:@"1.jpg"]];
        [scrollView addSubview:imageview1];

     
     
          UIImageView *imageview2 = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width*2, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
        [imageview2 setImage:[UIImage imageNamed:@"1.jpg"]];
         [scrollView addSubview:imageview2];
     
   
        UIImageView *imageview3 = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width*3, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
        [imageview3 setImage:[UIImage imageNamed:@"1.jpg"]];
        imageview3.userInteractionEnabled = YES;
     
     [scrollView addSubview:imageview3];
     
    
       
         UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];//在imageview3上加载一个透明的button
     
         [button setFrame:CGRectMake((self.view.bounds.size.width-200)/2, self.view.bounds.size.height - self.view.bounds.size.height / 5, 200, 40)];
     
     [button setTitle:@"点击开启" forState:UIControlStateNormal];
     button.titleLabel.font = [UIFont systemFontOfSize:22];
            [button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
         [imageview3 addSubview:button];
     button.titleLabel.font = [UIFont boldSystemFontOfSize:22];
     [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
     [self.view addSubview:scrollView];
     
     
     UIPageControl *page = [[UIPageControl alloc]initWithFrame:CGRectMake(self.view.bounds.size.width/2-30, self.view.bounds.size.height*7/8, 60, 20)];
     [self.view addSubview:page];
     page.numberOfPages = 4;
     self.page = page;
     [page addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)click:(UIPageControl *)page
{
    if (page.currentPage == 0) {
        [self.scrollview setContentOffset:CGPointMake(0, 0)];
    }
  else  if (page.currentPage == 1) {
        [self.scrollview setContentOffset:CGPointMake(self.view.bounds.size.width, 0)];
    }
   else  if (page.currentPage == 2) {
        [self.scrollview setContentOffset:CGPointMake(self.view.bounds.size.width*2, 0)];
    }
   else {
        [self.scrollview setContentOffset:CGPointMake(self.view.bounds.size.width*3, 0)];
    }
}


- (void)button:(UIButton *)but
{
    //美物推荐:
    GoodsMainViewController *recoCV = [[GoodsMainViewController alloc]init];
    UINavigationController *recoNavi = [[UINavigationController alloc]initWithRootViewController:recoCV];
    recoCV.tabBarItem.image = [UIImage imageNamed:@""];
    recoCV.title = @"美物推荐";

    
    
    //精选推物:
    QualityGoodsMainViewController *qualityCV = [[QualityGoodsMainViewController alloc]init];
    UINavigationController *qualityNavi = [[UINavigationController alloc]initWithRootViewController:qualityCV];;
    qualityCV.tabBarItem.image = [UIImage imageNamed:@""];
    qualityCV.title = @"精选推物";
    
    
    //个人主页:
    MyMainViewController *myCV = [[MyMainViewController alloc]init];
    UINavigationController *myNavi = [[UINavigationController alloc]initWithRootViewController:myCV];
    myCV.tabBarItem.image = [UIImage imageNamed:@""];
    myCV.title = @"个人主页";
    
    
    //大象推文:
    ElephantMainViewController *elephantCV = [[ElephantMainViewController alloc]init];
    UINavigationController *elephantNavi = [[UINavigationController alloc]initWithRootViewController:elephantCV];
    elephantCV.tabBarItem.image = [UIImage imageNamed:@""];
    elephantCV.title = @"大象推文";
    
    
    //美文推荐:
    ActicleMainViewController *acticleCV = [[ActicleMainViewController alloc]init];
    UINavigationController *acticleNavi = [[UINavigationController alloc]initWithRootViewController:acticleCV];
    acticleCV.tabBarItem.image = [UIImage imageNamed:@""];
    acticleCV.title = @"美文推荐";
    
    
    UITabBarController *tabC = [[UITabBarController alloc]init];
    tabC.viewControllers = @[recoNavi,qualityNavi,myNavi,elephantNavi,acticleNavi];
    
  
    [self presentViewController:tabC animated:NO completion:^{
    }];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
